//当前登录的用户信息
const key_current_login_user_info = 'key_current_login_user_info';

export default class LocalCacheMgr {
	static shareInstance() {
		if(!this.s_instance) {
			this.s_instance = new LocalCacheMgr();
		}
		return this.s_instance;
	}
	
	static destoryInstance() {
		s_instance = null;
	}
	
	setItemForkey(key, item) {
		try{
			uni.setStorageSync(key, item);
		} catch(err) {
			console.log('存储失败，key:' + key + ', item:' + JSON.stringify(item));
		}
	}
	
	getItemForKey(key) {
		try{
			return uni.getStorageSync(key);
		}catch(e){
			console.log('获取失败，key:' + key);
			return null;
		}
	}
	
	clearCache() {
		try{
			uni.clearStorageSync();
		} catch(err) {
			console.log('清空缓存失败...');
		}
	}
	
	getLoginUserInfo() {
		return this.getItemForKey(key_current_login_user_info);
	}
	
	setLoginUserInfo(userInfo) {
		this.setItemForkey(key_current_login_user_info, userInfo);
	}
}


LocalCacheMgr.s_instance = null;